<%--
  Created by IntelliJ IDEA.
  User: Teacher
  Date: 2025/4/1
  Time: 10:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户注册</title>
    <script>
        function checkUsername(){
            let xhr = new XMLHttpRequest();
            xhr.onreadystatechange = function(){
                if(xhr.readyState == 4 && xhr.status == 200){
                    document.getElementById("s1").innerHTML = xhr.responseText;
                }
            }
            let username = document.getElementById("username").value;
            // get请求
            // xhr.open("get","${pageContext.request.contextPath}/checkUsername?username="+username);
            // xhr.send(null);

            // post请求
            xhr.open("post","${pageContext.request.contextPath}/checkUsername");
            // 对于post请求,必须指定请求头中的数据格式
            // 通过Content-Type属性指定数据格式
            xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xhr.send("username="+username);
        }
    </script>
</head>
<body>
<h1>用户注册</h1>
<hr>
<form action="#" method="post" >
    用户名:<input type="text" id="username" name="username" onblur="checkUsername()"><span style="font-size: 12px;" id="s1"></span><br>
    密&nbsp;&nbsp;&nbsp;码:<input type="password" name="password"><br>
    电&nbsp;&nbsp;&nbsp;话:<input type="text" name="phone"><br>
    地&nbsp;&nbsp;&nbsp;址:<input type="text" name="address"><br>
    <input type="submit" value="注册">
</form>
</body>
</html>
